<template>
	<view v-if="info.name" :style="theme">
		<view class="box" :style="{backgroundImage: 'url(' + ossHost + '/member/20190326/yhq.png)'}">
			<view class="bt">{{info.name}}</view>
			<view>适用场馆：{{info.venueName}}</view>
			<view>适用时间：{{info.time}}</view>
			<view class="limit-2-line">适用项目：{{info.xm}}</view>
			<view class="lq" @click="lqBtn">立即领取</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				info: {},
				lqpd: false
			}
		},
		async onLoad(ops) {
			await this.$onLaunched;
			this.info = ops
			if (!this.userInfo || !this.userInfo.id) {
				this.$app.showToast('请先授权手机号登录小程序')
				this.$store.commit('logout')
				setTimeout(() => {
					// #ifdef MP
					this.jump('/pages/home/login')
					// #endif 
					// #ifdef H5
					this.jump('/pages/home/loginb')
					// #endif 
				}, 800)
			} else {
				this.getPd()
			}
		},
		onShow() {
			if(this.lqpd) {
				this.getPd()
			}
		},
		methods: {
			jump(url, params, a) {
				this.$app.jump(url, params, a);
			},
			jump2(url, params, a) {
				this.$app.jump2(url, params, a);
			},
			jump3(url, params, a) {
				this.$app.jump3(url, params, a);
			},
			getPd() {
				this.$app.ajax({
					api: this.$api.shareReceive(),
					data: {
						userId: this.userInfo.id,
						param: {
							type: '0',
							id: this.info.id
						}
					}
				}).then((res) => {
					this.lqpd = true
					if (res.errorCode === '000000') {
						if (res.record.id) {
							this.jump3('/pages/venue/ewm?code=', res.record.id)
						}
					}
				}).catch(() => {})
			},
			lqBtn() {
				this.$app.ajax({
					api: this.$api.shareReceive(),
					data: {
						userId: this.userInfo.id,
						param: {
							type: '1',
							id: this.info.id
						}
					}
				}).then((res) => {
					if (res.errorCode === '000000') {
						if (res.record.id) {
							this.jump3('/pages/venue/ewm?code=', res.record.id)
						} else {
							this.$app.showToast('无法领取了')
						}
					}
				}).catch(() => {})
			}
		},

	}
</script>
<style scoped lang="scss">
	.box {
		width: 690rpx;
		background-repeat: no-repeat;
		background-position: center center;
		background-size: 100% 100%;
		height: 418rpx;
		margin: 0 auto;
		padding: 48rpx 48rpx 0;
		font-size: 24rpx;
		line-height: 2.2;
		color: #ffffff;
		box-sizing: border-box;
	}

	.bt {
		font-size: 36rpx;
		font-weight: bolder;
		padding-bottom: 30rpx;
		line-height: 1;
		margin-bottom: 20rpx;
		border-bottom: 1px solid rgba(255, 255, 255, 0.3);
	}

	.lq {
		width: 192rpx;
		height: 60rpx;
		line-height: 60rpx;
		text-align: center;
		background: #FFFFFF;
		margin: 30rpx auto 0;
		border-radius: 30px;
		color: $color;
		font-size: 28rpx;
	}
</style>
